#include "head_c.h"

void changePath(user_info *info) {
    int path_len;
    char buf[1024] = {0};
    char *saveptr;
    char tempstr[256] = {0};
    strcpy(buf, info->command_str_goto);
    char *p = strtok_r(buf, "/", &saveptr);
    while(p != NULL) {
        printf("%s\n", p);
        if(strcmp(p, "..")) {
            strcpy(tempstr, info->path);
            sprintf(info->path, "%s/%s", tempstr, p);
        }
        else {
            path_len = strlen(info->path);
            while(info->path[path_len - 1] != '/') {
                info->path[path_len - 1] = '\0';
                path_len--;
            }
            info->path[path_len - 1] = '\0';
        }
        p = strtok_r(NULL, "/", &saveptr);
    }
    return;
}
